﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;


/*
 * This file is part of FrequencyAnalyzer
 *    
 * Copyright 2014 Dr. Jason M Pittman. All Rights Reserved.
 * www.deceptikrons.org
 *
 * is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 2 of the License.
 *
 * is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with . If not, see <http://www.gnu.org/licenses>.
 */


namespace FrequencyAnalyzer
{
    public partial class Main : Form
    {
        private string _selectedFile = String.Empty;

        public Main()
        {
            InitializeComponent();
        }

        private void btnAnalyze_Click(object sender, EventArgs e)
        {
            //load text file to frequencies dictionary
            FileLoader loader = new FileLoader();
            
            Dictionary<char, int> frequencies = loader.LoadFile( _selectedFile);

            //load frequencies into chart
            foreach (KeyValuePair<char, int> pair in frequencies)
            {
                Series series = this.chartFrequency.Series.Add(pair.Key.ToString());
                this.chartFrequency.Series[pair.Key.ToString()]["PointWidth"] = "1.75";

                series.Label = pair.Key.ToString() + "\n" + pair.Value.ToString();
                series.Points.Add(pair.Value);
            }   
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void loadFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.Filter = "Cipher Files (.ciph)|*.ciph";
            openFile.InitialDirectory = @"C:\ciphers";

            openFile.ShowDialog();

            _selectedFile = openFile.FileName;
        }

        private void Main_Load(object sender, EventArgs e)
        {

        }
    }
}
